package aop;


import org.aopalliance.intercept.Joinpoint;
import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

import java.util.Arrays;

@Aspect
public class UserServiceLogger {
    private static Logger log= Logger.getLogger(UserServiceLogger.class);
    public void before(JoinPoint jp){
        System.out.println("调用 " + jp.getTarget() + " 的 " + jp.getSignature().getName()
                + " 方法。方法入参：" + Arrays.toString(jp.getArgs()));
        System.out.println("前置");
    }
    public void afterReturning(JoinPoint jp, Object result) {
        System.out.println("调用 " + jp.getTarget() + " 的 " + jp.getSignature().getName()
                + " 方法。方法返回值：" + result);
        System.out.println("后置");
    }
    public void afterThrowing(JoinPoint jp, RuntimeException e) {
            System.out.println(jp.getSignature().getName()+"发生异常"+e);
    }
    @Pointcut("execution(* service.UserService.*(..)))")
    public void pointCut(){

    }


    @After("pointCut()")
    public void after(JoinPoint jp) {
        System.out.println("+++++llll++++3+++99+++++++++++我是最终增强");
    }
    @AfterReturning(pointcut ="pointCut()",returning = "returnValue")
    public void after2(JoinPoint jp,Object returnValue) {
        System.out.println("+++++llll++++3+++99+++++++++++我是最终增强"+returnValue);
    }
    public Object around(ProceedingJoinPoint jp) {
        System.out.println("ffffff");
        Object result;
        try {
            System.out.println("gggggggg");
            Object proceed = jp.proceed();
            result=proceed;
            System.out.println(result.toString());
            System.out.println("dfdsfasfdasd");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("ffff");
        }
        return "33333333333";
    }
}
